import React, { Component } from 'react';
import { TextInput, StatusBar, View, Image, Text, TouchableOpacity } from 'react-native';
import { unitWidth, unitHeight, height, width } from '../constants/AdapterUtil';
import { CodeInput, IconInput, MyInput1, CodeInput2 } from '../components/Input';
import { SubmitButton1 } from '../components/Button';
import TextUtil from '../constants/TextUtil';
import { MyHeader } from '../components/MyHeader';
import { postFetch } from '../constants/HttpExtension';
import { show } from '../constants/Toast';
import { api_account_forget, api_member_info_updatePassword, api_member_info_opinion } from '../constants/HttpServices';
import Colors from '../constants/Colors';

export default class OpinionScreen extends Component {

    constructor(props) {
        super(props)
        this.state = {
            opinion: '',
        }
    }

    componentDidMount() {

    }

    render() {
        return (
            <View style={{ flex: 1, alignItems: 'center', backgroundColor: Colors.colorF5 }}>
                <MyHeader leftImg={require('../res/ic_arrow_left.png')} leftClick={() => { this.props.navigation.pop() }} title='意见反馈' />
                <View style={this.props.style}>
                    <View style={{
                        width: width, minHeight: 300 * unitWidth, paddingHorizontal: 20 * unitWidth, marginTop: 5 * unitWidth,
                        backgroundColor: Colors.white, alignItems: 'flex-start', paddingVertical: 15 * unitWidth, flexDirection: 'row'
                    }}>
                        <View style={{ position: 'absolute', top: 26 * unitWidth, left: 25 * unitWidth }}>
                            <Image style={{ width: 20 * unitWidth, height: 21 * unitWidth }} source={require('../res/me_yjfk2.png')} resizeMode='stretch' />
                        </View>
                        <TextInput
                            style={{
                                fontSize: 16
                            }}
                            multiline={true}
                            onChangeText={(text) => {
                                this.onOpinionChange(text)
                            }}
                            maxLength={800}
                            placeholder='         请输入您的意见...'
                            value={this.state.opinion}
                        />
                    </View>
                </View>
                <SubmitButton1 style={{ marginTop: 208 * unitWidth }} text='确定' onPress={this.submit.bind(this)} />
            </View >
        )
    }

    onOpinionChange(text) {
        this.setState({
            opinion: '         ' + text.trim()
        })
    }

    submit() {
        if (this.state.opinion == '') {
            show('请输入您的意见...');
            return;
        }
        let params = {
            "content": this.state.opinion.trim(),
        }
        postFetch(api_member_info_opinion, params, {
            success: (response) => {
                show('提交成功');
                this.props.navigation.pop();
            },
            fail: (response) => {
                show(response.result.message);
            }
        })
    }
}